package com.celesea.workflow.core.vo;

import com.celesea.framework.util.CollectionKit;
import com.celesea.workflow.core.entity.WorkflowDefine;

import java.util.List;
import java.util.function.Function;

/**
 * @author JackYuan
 * @create 2017-11-28 12:30
 */
public class WorkflowDefineVo extends WorkflowDefine {
    private List<WorkflowNodeVo> nodes;

    public void initStartNodeId(String startNodeId) {
        if (CollectionKit.isNotEmpty(nodes)) {
            nodes.get(0).setId(startNodeId);
            this.setStartNodeId(startNodeId);
            this.setStartNodeName(nodes.get(0).getName());
        }
    }


    public void initNodeRelation(Function<List<WorkflowNodeVo>, ?> function) {
        if (CollectionKit.isNotEmpty(nodes)) {
            nodes.stream().forEach(item -> item.setWfId(this.getId()));
            function.apply(nodes);
        }
    }

    public WorkflowDefine toEntity() {
        return this;
    }

    public List<WorkflowNodeVo> getNodes() {
        return nodes;
    }

    public void setNodes(List<WorkflowNodeVo> nodes) {
        this.nodes = nodes;
    }


}
